<template>
  <div class="app-container bg">
    <!-- 数据区域 -->
    <div class="num-template">
      <el-row :gutter="10">
        <el-col :span="6" v-for="(item,index) in templateCount" :key="index">
          <div class="title">{{item.name}}</div>
          <div class="num">{{item.count}}</div>
        </el-col>
      </el-row>
    </div>
    <!-- 创作文章 -->
    <div class="create-article">
        <div class="title">
          <div class="title-left">创作内容</div>
          <div class="title-right" @click="toTaskPage">查看更多  <i class="el-icon-arrow-right"></i> </div>
        </div>
        <div class="article-list">
          <div class="article-item" v-for="(item,index) in taskList" :key="index" @click="onPreview(item)">
            <div class="article-item-con">
              <!-- 左侧图片 -->
              <div v-if="item.type=='IMAGE'" class="article-item-img">
                <img v-if="item.taskContent.imageUrl" class="article-item-img" :src="item.taskContent.imageUrl" @error="handleError"/>
                <img v-else class="article-item-img" src="@/assets/images/moren.png" alt="">
              </div>
              <div v-if="item.type=='NEWS'">
                <div v-if="item.taskContent.images">
                  <img v-if="sindex==0" class="article-item-img" v-for="(img,sindex) in item.taskContent.images" :src="img"  @error="handleError"/>
                </div>
                <img v-else class="article-item-img" src="@/assets/images/moren.png" alt="">
              </div>
              <div v-if="item.type=='VIDEO' || item.type=='DIGITAL_PERSON'" class="article-item-img">
                <!-- <video v-if="item.taskContent.videoPath" class="article-item-video" :src="item.taskContent.videoPath"></video> -->
                <img class="article-item-img" src="@/assets/images/moren.png" alt="">
              </div>
              <!-- 右侧文字 -->
              <div class="article-item-right">
                <el-tooltip class="item" :disabled="item.taskContent.title.length<12" :content="item.taskContent.title" placement="top">
                  <div class="article-item-title ellipsis">{{ item.taskContent.title }}</div>
                </el-tooltip>
                
                <div class="article-item-tag">
                  <div class="article-item-tag-item">
                      <div class="tag-name">情绪价值</div>
                      <div class="tag-value">{{ item.taskContent.emotionalScore || '--' }}</div>
                  </div>
                  <div class="article-item-tag-item">
                      <div class="tag-name">真实度</div>
                      <div class="tag-value">{{ item.taskContent.realityScore || '--' }}</div>
                  </div>
                  <div class="article-item-tag-item">
                      <div class="tag-name">引导力</div>
                      <div class="tag-value">{{ item.taskContent.totalScore || '--' }}</div>
                  </div>
                </div>
              </div>
              <div class="article-item-bottom">
                {{parseTime(new Date(item.createTime), '{y}年{m}月{d}日')}}   {{item.nickName}}创作 文章
              </div>
            </div>
          </div>
        </div>
        <!-- <div class="pagination">
          <pagination
            v-show="total>0"
            :total="total"
            :page-sizes="[8, 16, 24, 32, 40, 48]"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getTaskList"
          />
        </div> -->
    </div>
    <!-- 底部 -->
    <div class="main-footer">
      <!-- 创作灵感 -->
      <div class="inspiration-con">
        <div class="inspiration-title"> <img class="title-icon" src="@/assets/images/profile.jpg" alt="">创作灵感</div>
        <div class="inspiration-list">
            <div class="inspiration-item" v-for="topic in topicList" :key="topic.id">#{{topic.title}}#</div>
        </div>
      </div>
      <!-- 使用帮助 -->
      <div class="help-con">
        <div class="help-title"> <img class="title-icon" src="@/assets/images/profile.jpg" alt="">使用帮助</div>
        <div class="help-list">
          <div class="help-item" v-for="help in helpList" :key="help.id">#{{ help.title }}#</div>
        </div>
      </div>
    </div>
    <Preview ref="preview"></Preview>
  </div>
</template>

<script>
import { countTask, getTaskList } from "@/api/content/task";
import Preview from "./../task/components/Preview";
import { queryTopicList } from "@/api/material/material";
import { getHelpList } from '@/api/system/task.js'

export default {
  name: "Template",
  data() {
    return {
      total: 0,
      templateCount: [],
      queryParams: {
        pageNum: 1,
        pageSize: 8
      },
      taskList: [],
      defaultImg: require('@/assets/images/moren.png'),
      topicList: [], // 话题列表
      helpList: [], // 帮助列表
    };
  },
  components: {
    Preview
  },
  created() {
    this.getList();
    this.getTaskList()
    this.queryTopicList()
    this.getHelpList()
  },
  methods: {
    /** 查询内容制作模板列表 */
    getList() {
      this.loading = true;
      countTask(this.queryParams).then(response => {
        console.log(response,'列表');
        this.templateCount = response.data;
        this.loading = false;
      });
    },
    /**
     * 
     */
    getTaskList() {
      this.loading = true;
      getTaskList(this.queryParams).then(response => {
        console.log(response,'taskList');
        this.taskList = response.rows.map(item => {
          item.privateLoading = false;
          item.publicLoading = false;
          if (item.type == 'DIGITAL_PERSON') {
            item.taskContent = item.taskDigitalPerson
          } else if (item.type == 'VIDEO') {
            item.taskContent = item.taskVideo
          } else if (item.type == 'NEWS') {
            item.taskContent = item.taskNews
            console.log(item.taskContent.images,'ssdsd')
            item.taskContent.images = item.taskContent.images==null||item.taskContent.images==''?null:item.taskContent.images.split(',')
          }else{
            item.taskContent = item.taskImage
          }
          return item;
        });
        console.log(this.taskList);
        this.total = response.total;
        this.loading = false;
      });
    },
    /**
     * 图片路径404时展示默认图片
     * @param e 
     */
    handleError(e) {
        e.target.src = this.defaultImg;
    },
    /**
     * 预览
     * @param item 
     */
    onPreview(item) {
      console.log(item)
      // if(item.taskStatus == 'RUNNING'){
      //   return this.$modal.msgError("制作中，无法查看");
      // }
      this.$refs.preview.show(item)
    },
    // 获取话题列表
    queryTopicList() {
      queryTopicList().then(response => {
        console.log(response)
        this.topicList = response?.data || []; // 取7条数据
      });
    },
    getHelpList() {
      getHelpList().then(response => {
        console.log(response)
        this.helpList = response?.data || []; // 取7条数据
      });
    },
    toTaskPage() {
      this.$router.push({ path: '/content/task' });
    }
  }
};
</script>
<style lang="scss" scoped>
  .app-container{
    color: #fff;
  }
  .num-template{
    padding: 30px 0;
    background: rgba(255, 255, 255, .1);
    border-radius: 12px;
    text-align: center;
    .num{
      font-size: 40px;
      font-style: normal;
      font-weight: 700;
      margin-top: 20px;
      font-family: "DIN Alternate";
    }
  }
  .bg{
    background-image: url("../../../assets/images/content_bg.png");
    background-size: 25%;
    background-repeat: no-repeat;
    background-position: top right;
  }
  .create-article{
    background: rgba(255, 255, 255, .1);
    margin-top: 20px;
    border-radius: 12px;
    .title{
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 20px 20px 0;
      font-size: 18px;
      .title-right{
        font-size: 16px;
        cursor: pointer;
      }
      i{
        font-size: 14px;
      }
    }
    .pagination {
      overflow: hidden;
      .pagination-container {
        margin: 0 20px 40px;
        padding: 0 20px;
      }
    }
  }
  .article-list{
    display: flex;
    flex-wrap: wrap;
    margin: 10px;
    padding-bottom: 10px;
    &>.article-item{
      width: 25%;
      padding: 10px;
      // background: rgba(255, 255, 255, .1);
      // border-radius: 8px;
      .article-item-con{
          position: relative;
          width: 100%;
          height: 100%;
          background: rgba(255, 255, 255, .1);
          border-radius: 12px;
          padding: 20px 20px 56px;
          display: flex;
      }
    }
    .article-item-title{
      font-size: 18px;
      margin-bottom: 10px;
      width: 100%;
    }
    .article-item-img{
      width: 88px;
      height: 88px;
      border-radius: 8px;
    }
    .article-item-tag{
      display: flex;
      .tag-name{
        font-size: 14px;
        color: rgba(255, 255, 255, .6);
        font-family: "Alibaba PuHuiTi 2.0";
        margin-bottom: 10px;
        margin-right: 30px;
      }
      .tag-value{
        font-size: 16px;
        color: rgba(255, 255, 255, 1);
      }
    }
    .article-item-right{
      flex: 1;
      min-width: 0;
      margin-left: 16px;
    }
    .article-item-bottom{
      position: absolute;
      left: 20px;
      right: 20px;
      bottom: 20px;
      margin-top: -20px;
      font-size: 14px;
    }
  }
  .main-footer{
    display: flex;
    margin-top: 20px;
    .inspiration-con{
      flex: 1;
      background: rgba(255, 255, 255, .1);
      border-radius: 12px;
      margin-right: 20px;
      padding: 20px;
      .inspiration-title{
        font-size: 18px;
        margin-bottom: 20px;
      }
      .inspiration-list{
        font-size: 14px;
        display: flex;
        flex-flow: wrap;
        .inspiration-item{
          width: 288px;
          margin-bottom: 20px;
        }
      }
      .title-icon{
        width: 20px;
        height: 20px;
        vertical-align: middle;
        margin-bottom: 5px;
        margin-right: 5px;
      }
    }   
    .help-con{
      width: 628px;
      background: rgba(255, 255, 255, .1);
      border-radius: 12px;
      padding: 20px;
      .help-title{
        font-size: 18px;
        margin-bottom: 20px;
      }
      .help-list{
        font-size: 14px;
        display: flex;
        flex-flow: wrap;
        .help-item{
          width: 290px;
          margin-bottom: 20px;

        }
      }
      .title-icon{
        width: 20px;
        height: 20px;
        vertical-align: middle;
        margin-bottom: 5px;
        margin-right: 5px;
      }
    }   
  }
</style>
